SET(MODULE_NAME scdl-core)

FIND_PACKAGE(FLEX)
FIND_PACKAGE(BISON)

FILE(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/scdl/parser/*.hpp)
FILE(GLOB FILES ${PROJECT_SOURCE_DIR}/src/scdl/parser/*.cpp)
FILE(GLOB FLEX_FILES lexer.ll)
FILE(GLOB BISON_FILES parser.yy)

SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

FLEX_TARGET(SCDLLexer ${FLEX_FILES} ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
BISON_TARGET(SCDLParser ${BISON_FILES} ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
ADD_FLEX_BISON_DEPENDENCY(SCDLLexer SCDLParser)

ADD_LIBRARY(${MODULE_NAME} SHARED ${FLEX_SCDLLexer_OUTPUTS} ${BISON_SCDLParser_OUTPUTS} ${FILES} ${HEADERS} ${FLEX_FILES} ${BISON_FILES})
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES COMPILE_DEFINITIONS "PARSER_DEFINITION")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES LINK_INTERFACE_LIBRARIES "")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES SUFFIX ".so")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES OUTPUT_NAME ${MODULE_NAME})
INSTALL(TARGETS scdl-core DESTINATION .)
